package edu.sctu.yueding.activitys;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import edu.sctu.yueding.R;
import edu.sctu.yueding.config.CacheConfig;
import edu.sctu.yueding.utils.JumpUtils;
import edu.sctu.yueding.utils.UpdateManager;
import edu.sctu.yueding.utils.httputils.SharePreference;

/**
 * Created by Administrator on 2016/9/6.
 */
public class SettingsActivity extends BaseActivity {

    private RelativeLayout mLineExitRel,mAboutUs,mResetPasswordRel;
    private SharePreference sharePreference;
    private TextView back;
//    private ImageView newImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_settings);
        initSystemBar(this,0);
        init();
    }

    private void init() {

        mLineExitRel = (RelativeLayout) findViewById(R.id.id_personal_center_exit_rel);
        mAboutUs = (RelativeLayout) findViewById(R.id.id_settings_about_us);
        mResetPasswordRel = (RelativeLayout) findViewById(R.id.id_settings_update_password);
//        newImg = (ImageView) findViewById(R.id.setting_new);

        sharePreference = SharePreference.getInstance(this);

//        if (sharePreference.ifHaveShare(CacheConfig.CACHE_IS_UPDATE) && sharePreference.getBoolean(CacheConfig.CACHE_IS_UPDATE)){
//
//            newImg.setVisibility(View.VISIBLE);
//            newImg.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    new UpdateManager(SettingsActivity.this).showNoticeDialog();
//                }
//            });
//
//        }else {
//
//            newImg.setVisibility(View.INVISIBLE);
//        }

        back = (TextView) findViewById(R.id.id_settings_back_txt);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


        mAboutUs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                JumpUtils.jumpActivity(SettingsActivity.this,AboutUsActivity.class);
            }
        });

        mResetPasswordRel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                JumpUtils.jumpActivity(SettingsActivity.this,ResetPasswordActivity.class);
            }
        });


        mLineExitRel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                new AlertDialog.Builder(SettingsActivity.this).setTitle("是否退出登录？")
                        .setIcon(android.R.drawable.ic_dialog_info)
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // 点击“确认”后的操作

//                                    new AppManager().finishActivity(getActivity());
//                                    sharePreference.removeOneCache("portrait");
//                                    sharePreference.removeOneCache(CacheConfig.CACHE_PORTRAIT);
                                sharePreference.removeOneCache(CacheConfig.CACHE_PORTRAIT_PATH);
                                sharePreference.removeOneCache(CacheConfig.CACHE_TOKEN);
                                sharePreference.removeOneCache(CacheConfig.CACHE_USER_PASSWORD);
//                                sharePreference.removeOneCache(CacheConfig.CACHE_USER_NAME);
                                sharePreference.removeOneCache(CacheConfig.CACHE_USER_ID);
                                sharePreference.removeOneCache(CacheConfig.CACHE_USER_INTRODUCTION_SELF);
                                sharePreference.removeOneCache(CacheConfig.CACHE_NICKNMAE);

                                JumpUtils.jumpActivity(SettingsActivity.this, LoginActivity.class);

                            }
                        })
                        .setNegativeButton("否", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // 点击“返回”后的操作,这里不设置没有任何操作
                            }
                        }).show();

            }
        });
    }


}
